<template>
    <h2>修改</h2>
    <table border="1">
        <tr>
            <td>
                房型名称
            </td>
            <td>
                <select v-model="info.tId">
                    <option v-for="item in type" :value="item.tId">{{item.tName}}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>房号</td>
            <td>
                <input type="text" v-model="info.number"/>
            </td>
        </tr>
        <tr>
            <td>备注</td>
            <td>
                <input type="text" v-model="info.beizhu"/>
            </td>
        </tr>
        <tr>
            <td>上架/下架</td>
            <td>
                <input type="radio" v-model="info.state" :value="true"/>上架
                <input type="radio" v-model="info.state" :value="false"/>下架
            </td>
        </tr>
    <tr>
        <input type="button" value="修改" @click="Add"/>
    </tr>
    </table>
</template>
<script setup lang="ts">
    import {ref,onMounted} from 'vue';
    import axios from 'axios';
    import {useRouter,useRoute} from 'vue-router';
    const route=useRoute();
    const router=useRouter();

    const info=ref({
    nId: route.params.id,
    tId:1,
    number: "",
    beizhu: "",
    state: true
    })

    const type=ref([{
        tId:0,
        tName:""
    }])

    onMounted(()=>{
        Xia();
        FanTIan();
    })

    const Xia=()=>{
        axios.get("https://localhost:7029/api/RoomNumber/GetRoomTYpe/GetRoomTYpe")
        .then(res=>{
            console.log(res.data);
            type.value=res.data;
        })
        .catch(err=>{
            console.log(err);
        })
    }

    const Add=()=>{
        axios.put("https://localhost:7029/api/RoomNumber/Updatenumber/Updatenumber",info.value)
        .then(res=>{
            if(res.data>0){
                alert('修改成功');
                router.push({
                    name:"ShowRoomNumer"
                })
            }
            else{
                alert('修改失败');
            }
        })
    }

    const FanTIan=()=>{
        axios.get("https://localhost:7029/api/RoomNumber/FanTian/FanTian",{
            params:{
                id:route.params.id
            }
        })
        .then(res=>{
            info.value=res.data;

        })
        .catch(err=>{
            console.log(err);
        })
    }

</script>
